Golang bufio.ScanWords() function example
package bufio
ScanWords is a split function for a Scanner that returns each space-separated word of text, with surrounding spaces deleted. It will never return an empty string. The definition of space is set by unicode.IsSpace.
Golang bufio.ScanWords() function usage example
file, err := os.Open("words.txt")
if err != nil {
panic(err.Error())
}
defer file.Close()
reader := bufio.NewReader(file)
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
fmt.Printf("%s ", scanner.Text())
}
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Grep : How to grep for strings inside binary data
+10.1k Golang : Identifying Golang HTTP client request
+10.3k Golang : Convert file content to Hex
+15.2k Golang : Get timezone offset from date or timestamp
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+7.7k Golang : Mapping Iban to Dunging alphabets
+13.9k Golang : Get current time
+14.9k Golang : Submit web forms without browser by http.PostForm example
+16.8k Golang : Get own process identifier
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+8.9k Golang : GMail API create and send draft with simple upload attachment example